//
//  SaveTripDialog.m
//  Traveling
//
//  Created by 曹秀云 on 15/6/22.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司. All rights reserved.
//

#import "SaveTripDialog.h"
#import "CustomShowView.h"
#import "SelectDateView.h"

@interface SaveTripDialog()

@property (weak, nonatomic) IBOutlet UITextField *tripNameTextFiled;
@property (weak, nonatomic) IBOutlet UIButton *startDateButton;
@property (weak, nonatomic) IBOutlet UIButton *okBtn;
@property (nonatomic, copy) void(^reslutBlock)(NSString *name,NSString *dateStr);

@property (nonatomic, weak) CustomShowView *showView;
@end


@implementation SaveTripDialog

+(instancetype)tripDialogWithName:(NSString *)name dateStr:(NSString *)dateStr result:(void(^)(NSString *name,NSString *dateStr))result{
    SaveTripDialog *dialog = [[[NSBundle mainBundle] loadNibNamed:@"SaveTripDialog" owner:nil options:nil] lastObject];
    dialog.tripNameTextFiled.text = name;
    [dialog.startDateButton setTitle:dateStr forState:UIControlStateNormal];
    dialog.reslutBlock = result;
    return dialog;
}

- (IBAction)enterBtnClick:(id)sender {
    if (ISBLANK(self.tripNameTextFiled.text)) {
        [DialogUtils showTips:@"请填写行程名称"];
        return;
    }
    if (ISBLANK(self.startDateButton.currentTitle)) {
        [DialogUtils showTips:@"请填写出发日期"];
        return;
    }
    if (self.reslutBlock) {
        self.reslutBlock(self.tripNameTextFiled.text,self.startDateButton.currentTitle);
    }
}

- (IBAction)startDeteBtnClick:(UIButton *)sender {
    [self endEditing:YES];
    SelectDateView *dateView = [SelectDateView dateViewWithResult:^(NSString *dateStr, NSDate *date) {
        [self.startDateButton setTitle:dateStr forState:UIControlStateNormal];
        [self.showView hideWithanim:YES];
        self.showView = nil;
    }];
    dateView.width = SCREENW-16;
    dateView.height = 254;
    CustomShowView *showView = [[CustomShowView alloc] initWithCustomView:dateView];
    self.showView = showView;
    [self.showView showWithanim:YES];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self endEditing:YES];
}

@end
